.class public Lcom/brixd/niceapp/db/LocalCacheDao;
.super Ljava/lang/Object;
.source "LocalCacheDao.java"


# instance fields
.field private mDb:Lcom/brixd/niceapp/db/ZMDatabaseOpenHelper;


# direct methods
.method public constructor <init>(Landroid/content/Context;)V
    .registers 3
    .param p1, "context"    # Landroid/content/Context;

    .prologue
    .line 17
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 18
    new-instance v0, Lcom/brixd/niceapp/db/ZMDatabaseOpenHelper;

    invoke-direct {v0, p1}, Lcom/brixd/niceapp/db/ZMDatabaseOpenHelper;-><init>(Landroid/content/Context;)V

    iput-object v0, p0, Lcom/brixd/niceapp/db/LocalCacheDao;->mDb:Lcom/brixd/niceapp/db/ZMDatabaseOpenHelper;

    .line 19
    return-void
.end method

.method static synthetic access$000(Lcom/brixd/niceapp/db/LocalCacheDao;)V
    .registers 1
    .param p0, "x0"    # Lcom/brixd/niceapp/db/LocalCacheDao;

    .prologue
    .line 13
    invoke-direct {p0}, Lcom/brixd/niceapp/db/LocalCacheDao;->deleteExpiredData()V

    return-void
.end method

.method private deleteExpiredData()V
    .registers 8

    .prologue
    .line 37
    invoke-static {}, Ljava/util/Calendar;->getInstance()Ljava/util/Calendar;

    move-result-object v0

    .line 38
    .local v0, "curTime":Ljava/util/Calendar;
    const/4 v4, 0x5

    const/16 v5, -0x1e

    invoke-virtual {v0, v4, v5}, Ljava/util/Calendar;->add(II)V

    .line 39
    invoke-virtual {v0}, Ljava/util/Calendar;->getTimeInMillis()J

    move-result-wide v2

    .line 40
    .local v2, "expiredTime":J
    new-instance v4, Ljava/lang/StringBuilder;

    invoke-direct {v4}, Ljava/lang/StringBuilder;-><init>()V

    const-string v5, "DELETE FROM EstimateModels WHERE time_updated < "

    invoke-virtual {v4, v5}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v4

    invoke-virtual {v4, v2, v3}, Ljava/lang/StringBuilder;->append(J)Ljava/lang/StringBuilder;

    move-result-object v4

    invoke-virtual {v4}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v1

    .line 41
    .local v1, "sql":Ljava/lang/String;
    const-string v4, "sql"

    new-instance v5, Ljava/lang/StringBuilder;

    invoke-direct {v5}, Ljava/lang/StringBuilder;-><init>()V

    const-string v6, "/"

    invoke-virtual {v5, v6}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v5

    invoke-virtual {v5, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v5

    invoke-virtual {v5}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v5

    invoke-static {v4, v5}, Lcom/zuiapps/suite/utils/log/LogUtil;->v(Ljava/lang/String;Ljava/lang/String;)V

    .line 42
    const-class v5, Lcom/brixd/niceapp/db/LocalCacheDao;

    monitor-enter v5

    .line 43
    :try_start_3c
    iget-object v4, p0, Lcom/brixd/niceapp/db/LocalCacheDao;->mDb:Lcom/brixd/niceapp/db/ZMDatabaseOpenHelper;

    invoke-virtual {v4}, Lcom/brixd/niceapp/db/ZMDatabaseOpenHelper;->getWritableDatabase()Landroid/database/sqlite/SQLiteDatabase;

    move-result-object v4

    invoke-virtual {v4, v1}, Landroid/database/sqlite/SQLiteDatabase;->execSQL(Ljava/lang/String;)V

    .line 44
    monitor-exit v5
    :try_end_46
    .catchall {:try_start_3c .. :try_end_46} :catchall_4c

    .line 45
    iget-object v4, p0, Lcom/brixd/niceapp/db/LocalCacheDao;->mDb:Lcom/brixd/niceapp/db/ZMDatabaseOpenHelper;

    invoke-virtual {v4}, Lcom/brixd/niceapp/db/ZMDatabaseOpenHelper;->close()V

    .line 46
    return-void

    .line 44
    :catchall_4c
    move-exception v4

    :try_start_4d
    monitor-exit v5
    :try_end_4e
    .catchall {:try_start_4d .. :try_end_4e} :catchall_4c

    throw v4
.end method


# virtual methods
.method public close()V
    .registers 3

    .prologue
    .line 26
    new-instance v0, Ljava/lang/Thread;

    new-instance v1, Lcom/brixd/niceapp/db/LocalCacheDao$1;

    invoke-direct {v1, p0}, Lcom/brixd/niceapp/db/LocalCacheDao$1;-><init>(Lcom/brixd/niceapp/db/LocalCacheDao;)V

    invoke-direct {v0, v1}, Ljava/lang/Thread;-><init>(Ljava/lang/Runnable;)V

    .line 32
    invoke-virtual {v0}, Ljava/lang/Thread;->start()V

    .line 33
    return-void
.end method

.method public getEstimateModel(I)Lcom/brixd/niceapp/model/EstimateModel;
    .registers 9
    .param p1, "appId"    # I

    .prologue
    .line 49
    const/4 v2, 0x0

    .line 50
    .local v2, "model":Lcom/brixd/niceapp/model/EstimateModel;
    const/4 v0, 0x0

    .line 51
    .local v0, "cursor":Landroid/database/Cursor;
    new-instance v4, Ljava/lang/StringBuilder;

    invoke-direct {v4}, Ljava/lang/StringBuilder;-><init>()V

    const-string v5, "SELECT data, time_updated FROM EstimateModels WHERE app_id = "

    invoke-virtual {v4, v5}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v4

    invoke-virtual {v4, p1}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;

    move-result-object v4

    invoke-virtual {v4}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v3

    .line 54
    .local v3, "sql":Ljava/lang/String;
    :try_start_15
    const-string v4, "sql"

    new-instance v5, Ljava/lang/StringBuilder;

    invoke-direct {v5}, Ljava/lang/StringBuilder;-><init>()V

    const-string v6, "/"

    invoke-virtual {v5, v6}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v5

    invoke-virtual {v5, v3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v5

    invoke-virtual {v5}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v5

    invoke-static {v4, v5}, Lcom/zuiapps/suite/utils/log/LogUtil;->v(Ljava/lang/String;Ljava/lang/String;)V

    .line 55
    iget-object v4, p0, Lcom/brixd/niceapp/db/LocalCacheDao;->mDb:Lcom/brixd/niceapp/db/ZMDatabaseOpenHelper;

    invoke-virtual {v4}, Lcom/brixd/niceapp/db/ZMDatabaseOpenHelper;->getReadableDatabase()Landroid/database/sqlite/SQLiteDatabase;

    move-result-object v4

    const/4 v5, 0x0

    invoke-virtual {v4, v3, v5}, Landroid/database/sqlite/SQLiteDatabase;->rawQuery(Ljava/lang/String;[Ljava/lang/String;)Landroid/database/Cursor;

    move-result-object v0

    .line 56
    invoke-interface {v0}, Landroid/database/Cursor;->moveToFirst()Z

    move-result v4

    if-eqz v4, :cond_56

    .line 57
    new-instance v4, Lorg/json/JSONObject;

    const-string v5, "data"

    invoke-static {v0, v5}, Lcom/brixd/niceapp/db/DBHelper;->getString(Landroid/database/Cursor;Ljava/lang/String;)Ljava/lang/String;

    move-result-object v5

    invoke-direct {v4, v5}, Lorg/json/JSONObject;-><init>(Ljava/lang/String;)V

    invoke-static {v4}, Lcom/brixd/niceapp/model/EstimateModel;->parseEstimateModel(Lorg/json/JSONObject;)Lcom/brixd/niceapp/model/EstimateModel;

    move-result-object v2

    .line 58
    const-string v4, "time_updated"

    invoke-static {v0, v4}, Lcom/brixd/niceapp/db/DBHelper;->getLong(Landroid/database/Cursor;Ljava/lang/String;)J

    move-result-wide v4

    invoke-virtual {v2, v4, v5}, Lcom/brixd/niceapp/model/EstimateModel;->setTimeUpdatedInMillis(J)V
    :try_end_56
    .catch Ljava/lang/Exception; {:try_start_15 .. :try_end_56} :catch_5c
    .catchall {:try_start_15 .. :try_end_56} :catchall_66

    .line 64
    :cond_56
    if-eqz v0, :cond_5b

    .line 65
    invoke-interface {v0}, Landroid/database/Cursor;->close()V

    .line 69
    :cond_5b
    :goto_5b
    return-object v2

    .line 60
    :catch_5c
    move-exception v1

    .line 61
    .local v1, "e":Ljava/lang/Exception;
    :try_start_5d
    invoke-virtual {v1}, Ljava/lang/Exception;->printStackTrace()V
    :try_end_60
    .catchall {:try_start_5d .. :try_end_60} :catchall_66

    .line 64
    if-eqz v0, :cond_5b

    .line 65
    invoke-interface {v0}, Landroid/database/Cursor;->close()V

    goto :goto_5b

    .line 64
    .end local v1    # "e":Ljava/lang/Exception;
    :catchall_66
    move-exception v4

    if-eqz v0, :cond_6c

    .line 65
    invoke-interface {v0}, Landroid/database/Cursor;->close()V

    :cond_6c
    throw v4
.end method

.method public updateEstimateData(Lcom/brixd/niceapp/model/EstimateModel;)V
    .registers 10
    .param p1, "model"    # Lcom/brixd/niceapp/model/EstimateModel;

    .prologue
    .line 73
    const-string v1, "REPLACE INTO EstimateModels(app_id, data, time_updated) VALUES (?,?,?)"

    .line 75
    .local v1, "sql":Ljava/lang/String;
    :try_start_2
    const-string v2, "sql"

    new-instance v3, Ljava/lang/StringBuilder;

    invoke-direct {v3}, Ljava/lang/StringBuilder;-><init>()V

    const-string v4, "/"

    invoke-virtual {v3, v4}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v3

    invoke-virtual {v3, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v3

    const-string v4, "\n"

    invoke-virtual {v3, v4}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v3

    invoke-virtual {p1}, Lcom/brixd/niceapp/model/EstimateModel;->getAppId()I

    move-result v4

    invoke-virtual {v3, v4}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;

    move-result-object v3

    const-string v4, "-"

    invoke-virtual {v3, v4}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v3

    invoke-virtual {p1}, Lcom/brixd/niceapp/model/EstimateModel;->getSource()Ljava/lang/String;

    move-result-object v4

    invoke-virtual {v3, v4}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v3

    const-string v4, "-"

    invoke-virtual {v3, v4}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v3

    invoke-virtual {p1}, Lcom/brixd/niceapp/model/EstimateModel;->getTimeUpdatedInMillis()J

    move-result-wide v4

    invoke-virtual {v3, v4, v5}, Ljava/lang/StringBuilder;->append(J)Ljava/lang/StringBuilder;

    move-result-object v3

    invoke-virtual {v3}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v3

    invoke-static {v2, v3}, Lcom/zuiapps/suite/utils/log/LogUtil;->v(Ljava/lang/String;Ljava/lang/String;)V

    .line 76
    const-class v3, Lcom/brixd/niceapp/db/LocalCacheDao;

    monitor-enter v3
    :try_end_47
    .catch Ljava/lang/Exception; {:try_start_2 .. :try_end_47} :catch_75

    .line 77
    :try_start_47
    iget-object v2, p0, Lcom/brixd/niceapp/db/LocalCacheDao;->mDb:Lcom/brixd/niceapp/db/ZMDatabaseOpenHelper;

    invoke-virtual {v2}, Lcom/brixd/niceapp/db/ZMDatabaseOpenHelper;->getWritableDatabase()Landroid/database/sqlite/SQLiteDatabase;

    move-result-object v2

    const/4 v4, 0x3

    new-array v4, v4, [Ljava/lang/String;

    const/4 v5, 0x0

    invoke-virtual {p1}, Lcom/brixd/niceapp/model/EstimateModel;->getAppId()I

    move-result v6

    invoke-static {v6}, Ljava/lang/String;->valueOf(I)Ljava/lang/String;

    move-result-object v6

    aput-object v6, v4, v5

    const/4 v5, 0x1

    invoke-virtual {p1}, Lcom/brixd/niceapp/model/EstimateModel;->getSource()Ljava/lang/String;

    move-result-object v6

    aput-object v6, v4, v5

    const/4 v5, 0x2

    invoke-virtual {p1}, Lcom/brixd/niceapp/model/EstimateModel;->getTimeUpdatedInMillis()J

    move-result-wide v6

    invoke-static {v6, v7}, Ljava/lang/String;->valueOf(J)Ljava/lang/String;

    move-result-object v6

    aput-object v6, v4, v5

    invoke-virtual {v2, v1, v4}, Landroid/database/sqlite/SQLiteDatabase;->execSQL(Ljava/lang/String;[Ljava/lang/Object;)V

    .line 78
    monitor-exit v3

    .line 82
    :goto_71
    return-void

    .line 78
    :catchall_72
    move-exception v2

    monitor-exit v3
    :try_end_74
    .catchall {:try_start_47 .. :try_end_74} :catchall_72

    :try_start_74
    throw v2
    :try_end_75
    .catch Ljava/lang/Exception; {:try_start_74 .. :try_end_75} :catch_75

    .line 79
    :catch_75
    move-exception v0

    .line 80
    .local v0, "e":Ljava/lang/Exception;
    invoke-virtual {v0}, Ljava/lang/Exception;->printStackTrace()V

    goto :goto_71
.end method
